﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using System.Collections.Generic;
using System.Web.Services;
using Meqs.Utilities;
using Meqs.Logic.Interface;

public partial class TeacherEval_School_ScoreInput_MyEvaler : System.Web.UI.Page
{
    protected int RID
    {
        get
        {
            string g = Request.QueryString["id"];
            int temp = 0;
            if (int.TryParse(g, out temp))
            {
                return temp;
            }
            return -1;
        }
    }
    protected string KeyWord
    {
        get
        {
            string g = Request.QueryString["key"];
            return g;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HistoryID.Text = RID.ToString();
            btnBind_Click(null, null);
        }
    }
    protected void btnBind_Click(object sender, EventArgs e)
    {
        Hashtable ht = new Hashtable();
        ht.Add("SchoolMark",Common.GetConstSchoolMark());
        ht.Add("SrcID",Common.GetUserInfo().UID);
        ht.Add("HistoryID", RID);
        Repeater1.DataSource = Container<ITeacherEvalDesLogic>.Instance.GetDestTeacher(ht);
        Repeater1.DataBind(); 
    }
    [System.Web.Services.WebMethod]
    public static int SaveTeacher(int id,int[] ids)
    {
        Hashtable ht = new Hashtable();
        ht.Add("SchoolMark", Common.GetConstSchoolMark());
        ht.Add("SrcID", Common.GetUserInfo().UID);
        ht.Add("HistoryID", id);
        IList<TeacherInfo> tis = Container<ITeacherEvalDesLogic>.Instance.GetDestTeacher(ht);
        foreach (int i in ids)
        {
            if (!Check(tis,i))
            {
                TeacherEvalDes ted = new TeacherEvalDes();
                ted.DesID = i;
                ted.SrcID = Common.GetUserInfo().UID;
                ted.SchoolMark = Common.GetConstSchoolMark();
                ted.HistoryID = id;
                Container<ITeacherEvalDesLogic>.Instance.Create(ted);
            }
        }
        return 1;
    }
    [System.Web.Services.WebMethod]
    public static int DeleteTeacher(int historyid,int id)
    {
        Hashtable ht = new Hashtable();
        ht.Add("SchoolMark", Common.GetConstSchoolMark());
        ht.Add("SrcID", Common.GetUserInfo().UID);
        ht.Add("DesID", id);
        ht.Add("HistoryID", historyid);
        return Container<ITeacherEvalDesLogic>.Instance.DeleteAllEval(ht);
    }

    private static bool Check(IList<TeacherInfo> tis,int id)
    { 
        foreach(TeacherInfo t in tis)
        {
            if(t.RID == id)
            {
                return true;
            }
        }
        return false;
    }
}
